﻿import Taro, { Component } from '@tarojs/taro'
import { Swiper, SwiperItem, Image, View, Text } from '@tarojs/components'
import '../../assets/common.scss'
import CommonJs from '../../utils/common'
import './pointsdetails.scss'

export default class Index extends Component {
  constructor(props) {
    super(props);
    this.state = {
      result:[],
      pageNumber:0,//页码数
      scrollPd:false,//是否可滑动
      hasNextPage:false,//是否有下一页  
      norecords:'',
      money:0,
      totalUc:0,
      totalWdt:0,
      appmark:CommonJs.getmark(),
    }
  }
  config = {
    navigationBarTitleText: '加载中'
  }
  componentWillMount () {
    if(this.state.appmark=='xjzb'){
      Taro.setNavigationBarTitle({title:'自洽指数'})
    }
    else{
      Taro.setNavigationBarTitle({title:'贡献指数'})
    }
    var money =this.$router.preload.money;
    var totalUc =this.$router.preload.totalUc;
    var totalWdt =this.$router.preload.totalWdt;
      this.setState({ 
      	money:money,
      	totalUc:totalUc,
      	totalWdt:totalWdt,
	  })
    this.getdate(0)
  }
  componentDidShow () {
  	
  }
  getdate(pageNumber){
		var url='/crm/papi/v1.9/currency/platStatisticsQuery'
		var _this=this
		var dates={
  		size:10,
  		page:pageNumber
  	}
    CommonJs.ajaxRequest(url,dates,'GET',function(res){
    	if (res) {

  			if(res.data.totalPages>pageNumber){
  		  	var hasNextPage = true;
  		  }
  			else{
  				var hasNextPage = false;
  			}
	      var result = res.data.list
	      var results = _this.state.result
	      for(var i = 0; i < result.length; i++){
	        results.push(result[i]);
	      }
	      if (hasNextPage) {
	        _this.setState({
	          result: results,
	          znwns: '暂无数据',
	          pageNumber: res.data.page,
	          hasNextPage: hasNextPage,
	          scrollPd: true
	        })
	      }
	      else {
	        _this.setState({
	          result: results,
	          znwns: '暂无数据',
	          pageNumber: res.data.page,
	          hasNextPage: hasNextPage,
	          scrollPd: false
	        })
	      }
	    } else {
	      _this.setState({
	        znwns: '暂无数据'
	      })
	    }
  	},"wfw")
	}
	loadMore(){
	
    var _this = this
    var pd = _this.state.scrollPd
    if(pd) {
      //防止多次触发滑动到底部事件
      _this.setState({
        scrollPd: false//禁止下拉
      })
      var pageNumber = _this.state.pageNumber + 1
      _this.getdate(pageNumber)
    }else{
      var hasNextPage =  _this.state.hasNextPage
      if(hasNextPage){
        Taro.showToast({
          title:'正在加载数据...',
          icon: 'none',
          duration: 2000
        })
      }else{
        Taro.showToast({
          title:'没有更多数据啦！',
          icon: 'none',
          duration: 2000
        })
      }
    }
  }

  
  render () {
    const result = this.state.result
    const appmark = this.state.appmark
    return (
      <View className='page'>
        <ScrollView className='qun-mingxibo' scrollY='true' onScrollToLower={this.loadMore.bind(this,'')}>

          <View className='qun-keyong' style={appmark=='xjzb'?'':'display:none'}>
            <View className='qun-keyong1 qun-keyongs'>当前自洽指数</View>
            <View className='qun-keyong2 qun-keyongs'>{this.state.money}</View>
            <View className='qun-keyong3 qun-keyongs' style="width:auto;padding:0 20px;">
              <Text>平台总UC:{this.state.totalUc/100}</Text>
            </View>
            <View className='qun-keyong3 qun-keyongs' style="width:auto;padding:0 20px;margin-top:6px">
                <Text>平台WDT总释放:{this.state.totalWdt/100}</Text>
            </View>
          </View>

          <View className='qun-keyong' style={appmark=='xjzb'?'display:none':''}>
            <View className='qun-keyong1 qun-keyongs'>当前贡献指数</View>
            <View className='qun-keyong2 qun-keyongs'>{this.state.money}</View>
            <View className='qun-keyong3 qun-keyongs' style="width:auto;padding:0 20px;">
              <Text>平台总贡献:{this.state.totalUc/100}</Text>
            </View>
            <View className='qun-keyong3 qun-keyongs' style="width:auto;padding:0 20px;margin-top:6px">
                <Text>平台贡献总释放:{this.state.totalWdt/100}</Text>
            </View>
          </View>

          <View className='qun-mngxi'>数据明细</View>
          <View className='nodate' style={!result||result.length==0?'':'display:none'}>暂无数据</View>
          {result.map((item, index) => (
         	<View className='qun-mingxilist'>
              <View className='qun-mngxicont'>
                <View className='qun-mngxileft'>
                  <Text className='qun-minxizngs qun-reanao'>无备注</Text>
                  <Text className='qun-minxizngs qun-minxitit'>{item.statisticalDate.slice(0,4)+'-'+item.statisticalDate.slice(4,6)+'-'+item.statisticalDate.slice(6)}</Text>
                </View>
                <View className='qun-mngxiright'>
                  <Text style="margin-top:0" className='qun-minxizngs qun-minxijine qun-colors'>{item.indexK}</Text>
                </View>
              </View>
          </View>
          ))}
        </ScrollView>
      </View>
    )
  }
}

 